/*
 * @Author: szx
 * @Date: 2021-10-25 10:04:58
 * @LastEditTime: 2021-10-25 11:27:58
 * @Description:
 * @FilePath: \leetcode\240\240.go
 */
package main

import (
	"fmt"
	"strconv"
	"strings"
)

func searchMatrix(matrix [][]int, target int) bool {
	m, n := len(matrix), len(matrix[0])
	x, y := 0, n-1
	for x < m && y > 0 {
		if target == matrix[x][y] {
			return true
		} else if target > matrix[x][y] {
			x++
		} else {
			y--
		}
	}
	return false
}
func generateArr(str string) []int {
	s := strings.TrimLeft(str, "[")
	s = strings.TrimRight(s, "]")
	strArr := strings.Split(s, ",")
	res := make([]int, len(strArr))
	for index, val := range strArr {
		res[index], _ = strconv.Atoi(val)
	}
	return res
}

func generateArr2(str string) [][]int {
	s := strings.TrimLeft(str, "[")
	s = strings.TrimRight(s, "]")
	strArr := strings.Split(s, "],")
	res := make([][]int, 0)
	for _, str := range strArr {
		strAr := strings.TrimLeft(str, "[")
		strA := strings.Split(strAr, ",")
		tmp := make([]int, len(strA))
		for index, val := range strA {
			tmp[index], _ = strconv.Atoi(val)
		}
		res = append(res, tmp)
	}
	return res
}
func main() {
	arr := generateArr2("[[1,4,7,11,15],[2,5,8,12,19],[3,6,9,16,22],[10,13,14,17,24],[18,21,23,26,30]]")
	fmt.Printf("%v", arr)
	// println(searchMatrix(arr, 20))
}
